/**
 * 首页模块
 */
define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";

	
	var base;

	var async = require("../../custom/base/component-async.js");
	
	var validate = require("../../custom/base/component-validate.js");
	
	require("../../custom/base/component-md5.js");
		

	//分享模块
	require.async(["../../custom/share/module-share.js"], function(share) {
		
		  share.init(share);
	  });
	  
	exports.init=function(m) {
		
		window.$ldh_index = m;
		
		base=$ldh_base;
		
		base.setFromPage("index");
		
		//加这段是为了适应在微信里使用支付宝支付时丢失cookie
		var userId=base.getParameter("userId");
		var loginSign=base.getParameter("loginSign");
		if(!validate.isNull(userId) && !validate.isNull(loginSign)){
			
			base.setCookie("userId",userId);
			base.setCookie("loginSign",loginSign);
		}
		
		exports.getAdList();
	};
	
	//获取广告列表
	exports.getAdList=function(){
		
		base.showLoading();
		
		var params = {
				pageSize:10,
				currentPage:1,
				channel:"01",
				cityId:"440100",
				sign:MD5(10+""+1)
		};
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shop/Discover/getAdList.do", params));
						
						
						if(data["code"]==1){
							
							var htmlStr="";
							for(var i=0;i<data["adList"].length;i++){
								
								//广告类型(01网页链接,02店铺主页,03店铺列表,04商品详情,05商品列表)
								
								if(data["adList"][i]["adType"]=="01"){
									htmlStr+='<div class="mod_01"><a rel="external" href="'+data["adList"][i]["adLink"]+'"><img src="'+fileOpenSourceUrl+data["adList"][i]["adPic"]+'" alt="'+data["adList"][i]["adTitle"]+'"></a></div>';
								
								}else if(data["adList"][i]["adType"]=="02"){
									//htmlStr+='<div class="mod_01"><a href=javascript:window.location.href="?shopId='+data["adList"][i]["adLink"]+'#ldhStore"><img src="'+fileOpenSourceUrl+data["adList"][i]["adPic"]+'" alt="'+data["adList"][i]["adTitle"]+'"></a></div>';
									htmlStr+='<div class="mod_01"><a rel="external" href="'+ctx+'/h5/shopIndex/'+data["adList"][i]["adLink"]+'.shtml"><img src="'+fileOpenSourceUrl+data["adList"][i]["adPic"]+'" alt="'+data["adList"][i]["adTitle"]+'"></a></div>';

								
								}else if(data["adList"][i]["adType"]=="03"){
									//htmlStr+='<div class="mod_01"><a rel="external" href="'+data["adList"][i]["adLink"]+'"><img src="'+fileOpenUrl+data["adList"][i]["adPic"]+'" alt="'+data["adList"][i]["adTitle"]+'"></a></div>';
								}else if(data["adList"][i]["adType"]=="04"){
									//htmlStr+='<div class="mod_01"><a href=javascript:window.location.href="?merchandiseId='+data["adList"][i]["adLink"]+'#ldhGoods"><img src="'+fileOpenSourceUrl+data["adList"][i]["adPic"]+'" alt="'+data["adList"][i]["adTitle"]+'"></a></div>';
									htmlStr+='<div class="mod_01"><a rel="external" href="'+ctx+'/h5/merDetail/'+data["adList"][i]["adLink"]+'.shtml"><img src="'+fileOpenSourceUrl+data["adList"][i]["adPic"]+'" alt="'+data["adList"][i]["adTitle"]+'"></a></div>';

								}else if(data["adList"][i]["adType"]=="05"){
									//htmlStr+='<div class="mod_01"><a rel="external" href="'+data["adList"][i]["adLink"]+'"><img src="'+fileOpenUrl+data["adList"][i]["adPic"]+'" alt="'+data["adList"][i]["adTitle"]+'"></a></div>';
								}
								
							}
							
							$("#ldhHome .slide_01").html(htmlStr);
							
							if ($(".banner_scroll").width()){
								   winWidth = $(".banner_scroll").width()-20;
							}


							//{"data":[{"advertisementId":"201404212342200000002","advertisementName":"签到送积分","channel":"1","createName":"15","createTime":"2014-04-21 23:42:21","memo":" ","pictureUrl":"/terminal/apks//14012461023383767473.png","sort":0,"updateName":"","updateTime":"","url":"http://mall.jekun.com/api/app/ad/banner-1.jsp"},{"advertisementId":"201405131703180004","advertisementName":"生活好帮手","channel":"1","createName":"15","createTime":"2014-05-13 17:03:18","memo":"","pictureUrl":"/terminal/apks//14012487172730340762.png","sort":0,"updateName":"15","updateTime":"2014-07-26 00:53:42","url":"http://mall.jekun.com/api/app/ad/banner-4.jsp"},{"advertisementId":"201405131002560003","advertisementName":"兑兑付APP闪亮登场","channel":"1","createName":"15","createTime":"2014-05-13 10:02:56","memo":"","pictureUrl":"/terminal/apks//14012461349110883001.png","sort":0,"updateName":"","updateTime":"","url":"http://mall.jekun.com/api/app/ad/banner-3.jsp"}],"code":"1","message":"调用成功"}
							$("#slide_01,.mod_01,.mod_01 img,.banner_scroll").css("width",winWidth);
							if(document.getElementById("slide_01")){
								var scrollContNum=document.getElementById("slide_01").getElementsByTagName("div").length,slide_01 = new ScrollPic();
								slide_01.scrollContId   = "slide_01"; //内容容器ID
								slide_01.dotListId      = "slide_01_dot";//点列表ID
								slide_01.dotOnClassName = "selected";
								slide_01.arrLeftId      = "sl_left"; //左箭头ID
								slide_01.arrRightId     = "sl_right";//右箭头ID
								slide_01.scrollContNum  = scrollContNum;
								slide_01.frameWidth     = winWidth;
								slide_01.pageWidth      = winWidth;
								slide_01.upright        = false;
								slide_01.speed          = 20;
								slide_01.space          = 30;
								slide_01.autoPlayTime   = 3; //秒 
								slide_01.initialize(); //初始化
							}	

							
						}
						
						base.cancelLoading();
						
		}))().start();
			
	};
	

	
	
});